#! /bin/sh -vx
# $Id$
# Copyright 2018 Karl Berry <tex-live@tug.org>
# You may freely use, modify and/or distribute this file.

BinDir=${BinDir:-.}
ExeExt=${ExeExt:-}
_uppltotf=$BinDir/uppltotf$ExeExt
_uptftopl=$BinDir/uptftopl$ExeExt

test -d uptests || mkdir -p uptests

TEXMFCNF=$srcdir/../kpathsea
export TEXMFCNF

DIFF="diff"
# pre-generated test results in the repository are stored in LF
# but the output might be written in CRLF on some platform.
# if 'diff --strip-trailing-cr' is available, exploit it.
# (useful for tests on win32 binaries run on MSYS shell)
$DIFF --strip-trailing-cr $0 $0 \
  && DIFF="diff --strip-trailing-cr" || echo

# Test inputs
testdir=$srcdir/uptexdir/tests

# Testing upPLtoTF/upTFtoPL for huge GLUEKERN table
# with rearrangement.
for font in gkhugeok; do

  # This test is constructed as a cycle, since JPL source
  # of gkhugeok.tfm is so large.
  $_uptftopl -verbose $testdir/$font.tfm uptests/y$font.pl && \
  $_uppltotf -verbose uptests/y$font.pl uptests/y$font.tfm && \
  cmp $testdir/$font.tfm uptests/y$font.tfm && echo || exit 1

done

for font in gkhugeng; do

  # Fifth byte of the JFM (= lf; length of the whole file)
  # must not exceed 2^{15}-1; check that and exit with an
  # error message, instead of trying to allocate too much.
  # The invalid gkhugeng.tfm was erroneously created before
  # web2c/pltotf.ch change 2017-09-10, due to overflow
  $_uptftopl $testdir/$font.tfm uptests/y$font.pl \
    2>uptests/y$font.err && exit 1 || echo
  $DIFF $testdir/$font.err uptests/y$font.err && echo || exit 2

done

